package com.companion.model

/**
 * Created by lh on 2017/5/24.
 * 响应类
 */
class Response {
    //结果码 0：失败，1：成功
    var code: Int = 0
    //提示信息
    var msg: String? = null
    //返回数据
    var data: Any? = null

    constructor(code: Int) {
        this.code = code
    }

    constructor(code: Int, msg: String) {
        this.code = code
        this.msg = msg
    }

    constructor(code: Int, msg: String, data: Any) {
        this.code = code
        this.msg = msg
        this.data = data
    }

    constructor(code: Int, data: Any) {
        this.code = code
        this.data = data
    }

    companion object {

        fun success(): Response {
            return Response(1)
        }

        fun success(msg: String): Response {
            return Response(1, msg)
        }

        fun success(data: Any): Response {
            return Response(1, data)
        }

        fun failure(): Response {
            return Response(0)
        }

        fun failure(msg: String): Response {
            return Response(0, msg)
        }

        fun data(data: Any): Response {
            return Response(1, data)
        }

        fun failure(data: Any): Response {
            return Response(0, data)
        }

    }
}
